//
//  TeacherEvalutionCell.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/4/10.
//  Copyright (c) 2017 蓝布鲁. All rights reserved.
//

#import "TeacherEvalutionCell.h"


@interface TeacherEvalutionCell ()
// 视图
@property (nonatomic, retain)UILabel *studentNameLabel;          // 学生名
@property (nonatomic, retain)UILabel *evalutionLabel;            // 评价
@property (nonatomic, retain)NSMutableArray *imageArray;        // 评分

@end

@implementation TeacherEvalutionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier {
    if(self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupView];
    }
    return self;
}

-(void)setupView {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // 学生名
    self.studentNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 150, 17)];
    self.studentNameLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.studentNameLabel];

    // 评价
    self.evalutionLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.studentNameLabel.bottomY+10, SCREEN_WIDTH-20, 20)];
    self.evalutionLabel.numberOfLines = 0;
    self.evalutionLabel.font = [UIFont systemFontOfSize:12];
    self.evalutionLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.evalutionLabel];

}

- (void)setModel:(TeacherEvalutionModel *)model {
    _model = model;
    // 清空评分图片
    [self removeSubViews:self.imageArray];
    self.imageArray = [[NSMutableArray alloc] init];

    // 学生名
    self.studentNameLabel.text = model.s_name;

    // 评价
    self.evalutionLabel.text = model.evaluationitem;
    self.evalutionLabel.height = [model.evaluationitem heightWithFont:[UIFont systemFontOfSize:12] width:SCREEN_WIDTH-20];

    // 评分图片
    NSInteger count = self.model.script;
    for (int i = 0; i < count; ++i) {
        CGFloat w = 20;
        CGFloat h = 20;
        // 屏幕宽度 - ((星星坐标+1)*(空隙+宽度))
        CGFloat x = SCREEN_WIDTH - ((i+1) * (10 + w));
        CGFloat y = 10;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        imageView.image = [UIImage imageNamed:@"star_orange"];
        [self.contentView addSubview:imageView];
        [self.imageArray addObject:imageView];
    }


    [self setupAutoHeightWithBottomView:self.evalutionLabel bottomMargin:5];
}

@end
